from functools import wraps


def singleton(cls):
    """@singleton：单例模式 确保类只有一个实例"""
    instances = {}
    def wrapper(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]
    return wrapper

def async_singleton(cls):
    """异步安全的单例模式装饰器"""
    instances = {}

    @wraps(cls)
    async def wrapper(*args, **kwargs):
        if cls not in instances:
            instances[cls] = cls(*args, **kwargs)
        return instances[cls]
    return wrapper